<template>
	<view class="container">
		<view class="commonNavBar">
			<view class="status-fill" :style="{height:statusBarHeight+'px'}"></view>

			<view class="nav-bar">
				<view class="text">我的</view>
				<view class="operatingArea">运营区域</view>
			</view>
		</view>
		<view class="fill" :style="{height:(statusBarHeight*2+navigationBarHeight)+'rpx'}"></view>

		<!-- 用户框 -->
		<view class="profile-card">
			<image class="avatar" src="/static/user.png" />
			<view class="user-info">
				<text class="username">用户名</text>
				<text class="role">共享骑行运维人员</text>
				<text class="phone">13535550719</text>
			</view>
			<!-- 动态显示区域 -->
			<button class="region-button" @click="openRegionModal">
				{{ selectedRegion }}
			</button>
		</view>

		<!-- 自定义弹窗 -->
		<view v-if="isRegionModalVisible" class="modal-container">
			<view class="modal-content">
				<view class="modal-header">
					<text>选择运营区域</text>
					<input type="text" placeholder="搜索区域" v-model="searchQuery" class="search-input" />
				</view>
				<view class="modal-body">
					<scroll-view scroll-y class="region-list">
						<view v-for="(region, index) in filteredRegions" :key="index" class="region-item"
							@click="selectRegion(region)">
							{{ region }}
						</view>
					</scroll-view>
				</view>
				<view class="modal-footer">
					<button class="cancel-button" @click="closeRegionModal">取消</button>
				</view>
			</view>
		</view>



		<!-- 列表 -->
		<view class="section">
			<view class="list">
				<!-- 获取新版本 -->
				<view class="row" @click="getNewVersion">
					<view class="left">
						<uni-icons type="download-filled" size="20"></uni-icons>
						<view class="text">获取新版本</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<!-- 新功能介绍 -->
				<view class="row" @click="goToFeatureIntro">
					<view class="left">
						<uni-icons type="info-filled" size="20"></uni-icons>
						<view class="text">新功能介绍</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<!-- 意见反馈 -->
				<view class="row" @click="goToFeedback">
					<view class="left">
						<uni-icons type="chat-filled" size="20"></uni-icons>
						<view class="text">意见反馈</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<!-- 联系客服 -->
				<view class="row" @click="contactCustomerService">
					<view class="left">
						<uni-icons type="phone-filled" size="20"></uni-icons>
						<view class="text">联系客服</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
				<!-- 退出登录 -->
				<view class="row" @click="logout">
					<view class="left">
						<uni-icons type="clear" size="20"></uni-icons>
						<view class="text">退出登录</view>
					</view>
					<view class="right">
						<uni-icons type="right" size="15" color="#aaa"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<navigator url="/pages/Pullup/Pullup">上拉测试</navigator>
	</view>
</template>

<script setup>
	import {
		computed,
		ref
	} from 'vue'
	import {
		onLoad,
		onLaunch
	} from '@dcloudio/uni-app'
	const statusBarHeight = ref(0);
	const navigationBarHeight = ref(114);


	onLoad(() => {
		statusBarHeight.value = uni.getSystemInfoSync().statusBarHeight;

	})


	const goToAccountManagement = () => {

		uni.navigateTo({
			url: '/pages/account-management/account-management'
		});
	};

	const getNewVersion = () => {
		uni.showToast({
			title: '已是最新版本',
			icon: 'success'
		});
	};

	const goToFeatureIntro = () => {
		uni.navigateTo({
			url: '/pages/featureIntro/featureIntro'
		});
	};

	const goToFeedback = () => {
		uni.navigateTo({
			url: '/pages/feedback/feedback'
		});
	};

	const contactCustomerService = () => {
		uni.makePhoneCall({
			phoneNumber: '13535550719'
		});
	};


	const isRegionModalVisible = ref(false); // 控制弹窗显示与隐藏
	const selectedRegion = ref("东城区"); // 保存选中的区域
	const searchQuery = ref(''); // 搜索框内容

	// 模拟的区域列表数据
	const regions = ref(['东城区', '西城区', '南城区', '北城区', '东西湖区', '青山区']);

	// 根据搜索内容动态过滤区域列表
	const filteredRegions = computed(() => {
		return regions.value.filter((region) =>
			region.includes(searchQuery.value)
		);
	});

	// 打开弹窗
	const openRegionModal = () => {
		isRegionModalVisible.value = true;
	};

	// 关闭弹窗
	const closeRegionModal = () => {
		isRegionModalVisible.value = false;
	};

	// 选择区域
	const selectRegion = (region) => {
		selectedRegion.value = region; // 更新选中的区域
		closeRegionModal(); // 关闭弹窗
		uni.showToast({
			title: `已选择区域：${region}`,
			icon: 'success',
		});
	};

	const logout = () => {
		uni.showModal({
			title: '提示',
			content: '确定要退出登录吗？',
			success: function(res) {
				if (res.confirm) {
					uni.clearStorage();
					uni.reLaunch({
						url: '/pages/login/login'
					});
				}
			}
		});
	};
</script>

<style lang="scss" scoped>
	.container {
		// padding: 0 30rpx;
	}

	.nav-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;

		.text {
			padding-left: 40rpx;
			font-size: 40rpx;
			line-height: 1.5em;
			font-weight: 800;
		}

		.operatingArea {
			padding-right: 40rpx;
		}
	}

	.profile-card {
		display: flex;
		align-items: center;
		position: relative;
		padding: 60rpx 40rpx;
		background-color: #4caf50;
		border-radius: 20rpx;
		color: #ffffff;
		cursor: pointer;

		.avatar {
			width: 100rpx;
			height: 100rpx;
			border-radius: 50%;
			margin-right: 30rpx;
		}

		.region-button {
			position: absolute;
			top: 20rpx;
			right: 20rpx;
			width: 200rpx;
			height: 60rpx;
			padding: 0;
			/* 去掉多余的内边距 */
			display: flex;
			justify-content: center;
			/* 水平居中 */
			align-items: center;
			/* 垂直居中 */
			background-color: #ffffff;
			color: #4caf50;
			border: none;
			border-radius: 10rpx;
			cursor: pointer;
			font-size: 20rpx;
		}



		.user-info {
			display: flex;
			flex-direction: column;
			margin-left: 30rpx;
		}

		.username {
			font-size: 40rpx;
			font-weight: bold;
		}

		.company {
			font-size: 32rpx;
			color: #ffffff;
			margin-top: 5rpx;
		}

		.role {
			font-size: 28rpx;
			margin-top: 5rpx;
			color: #ffffff;
		}

		.phone {
			font-size: 28rpx;
			margin-top: 5rpx;
			color: #ffffff;
		}

	}


	.modal-container {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, 0.5);
		display: flex;
		align-items: center;
		justify-content: center;
		z-index: 3;
	}

	.modal-content {
		width: 80%;
		background: #fff;
		border-radius: 20rpx;
		overflow: hidden;

		.modal-header {
			padding: 32rpx 32rpx 0 32rpx;
			border-bottom: 1px solid #f0f0f0;

			.search-input {
				width: calc(100% - 24rpx);
				/* 计算宽度以避免与父容器冲突 */
				height: 100%;
				margin: 12rpx auto;
				padding: 16rpx 24rpx;
				/* 均匀的内边距 */
				font-size: 28rpx;
				border: 1rpx solid #ccc;
				/* 边框颜色 */
				border-radius: 16rpx;
				/* 圆角输入框 */
				outline: none;
				box-sizing: border-box;
				/* 确保宽度包含内边距和边框 */
				transition: border-color 0.2s;
			}

			.search-input:focus {
				border-color: #4caf50;
				/* 聚焦时高亮边框 */
				background-color: #f9f9f9;
				/* 聚焦时背景微微变亮 */
			}

		}

		.modal-body {
			max-height: 400rpx;
			overflow-y: auto;

			.region-list {
				.region-item {
					padding: 20rpx;
					border-bottom: 1rpx solid #f0f0f0;
					cursor: pointer;

					&:hover {
						background-color: #f0f0f0;
					}
				}
			}
		}

		.modal-footer {
			display: flex;
			justify-content: flex-end;
			padding: 32rpx;

			.cancel-button {
				background: linear-gradient(135deg, #4caf50, #66bb6a);
				/* 绿色渐变背景 */
				color: #fff;
				padding: 10rpx 70rpx;
				border-radius: 16rpx;
				font-size: 28rpx;
				cursor: pointer;
				border: none;
				box-shadow: 0px 8rpx 12rpx rgba(0, 0, 0, 0.1);
				transition: all 0.3s ease;
			}
		}
	}

	.section {
		width: 690rpx;
		margin: 50rpx auto;
		border: 1rpx solid #eee;
		border-radius: 10rpx;
		box-shadow: 0 0 30rpx rgba(0, 0, 0, 0.1);

		.uni-icons {
			color: #4caf50 !important;
		}

		.list {
			.row {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 30rpx;
				height: 100rpx;
				border-bottom: 1rpx solid #eee;

				&:last-child {
					border-bottom: 0;
				}

				.left {
					display: flex;
					align-items: center;

					.text {
						padding-left: 20rpx;
						color: #666;
					}
				}

				.right {
					display: flex;
					align-items: center;

					.text {
						padding-left: 28rpx;
						color: #aaa;
					}
				}
			}
		}
	}
</style>